:-include('main.pl').

check_end(Board, Winner):-
                 rotate_board(Board, B),
                 check_endgame(1, B, 0),
                 Winner is 1,
                 !.
                 
check_end(Board, Winner):-
                 check_endgame(2, Board, 0),
                 Winner is 2,
                 !.
				 
check_end(_, Winner):-
                 Winner is 0,
                 !.				 
                 
initial_game(Board):-
					board_players_towns(Board).
				 
execute(Player, Movement, Board, UltimateBoard):-
				(Player == 1 -> rotate_board(Board, NB); NB = Board),
                sub_atom(Movement,0,1,_, XX0), number_chars(X0, [XX0]),
                sub_atom(Movement,1,1,_, YY0), number_chars(Y0, [YY0]),
                sub_atom(Movement,2,1,_, XX1), number_chars(X1, [XX1]),
                sub_atom(Movement,3,1,_, YY1), number_chars(Y1, [YY1]),
                check_play(Player, X0, Y0, X1, Y1, NB, NewBoard, _),
				(Player == 1 -> rotate_board(NewBoard, NBB); NBB = NewBoard),
				NBB = UltimateBoard, !.
				
execute(_, _, _, -1).				